package com.itfenghuang.day09;

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class A00_课下作业 {
    public static void main(String[] args) throws IOException {

//        method();
//        method1();
//        method2();
//        method3();

        // 5.从控制台接收3名学员的信息，每条进行存储到一个Student对象中，
        // 将多个Student对象存储到一个集合中。
        // 输入完毕后，将所有学员信息存储到文件Student.txt中。
        //每名学员信息存储一行，多个属性值中间用逗号隔开。比如: zhangsan,18,男
        Scanner sc = new Scanner(System.in);
        FileWriter fw = new FileWriter("D:\\it\\student.txt");
        ArrayList<Student> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            Student stu = new Student();
            System.out.println("请输入");
            String s = sc.nextLine();
            System.out.println("年龄");
            String s1 = sc.nextLine();
            System.out.println("性别");
            String s2 = sc.nextLine();
            stu.setName(s);
            stu.setAge(s1);
            stu.setSex(s2);
            list.add(stu);
            fw.write(s+" "+s1+" "+s2);
            fw.write("\r\n");
        }
        System.out.println(list);
        fw.close();

//        for (int i = 0; i < 3; i++) {
//
//            String s = sc.nextLine();
//            String[] str=s.split(",");
//            Student stu=new Student(str[0],Integer.parseInt(str[1]),str[3]);
//            list.add(stu);
//        }
//        for (Student student : list) {
//            fw.write(student.getName()+""+student.getAge()+""+student.getSex(););
//            fw.write("\r\n");
//        }




    }

    private static void method3() throws IOException {
    //4.请用户从控制台输入信息，程序将信息存储到文件Info.txt中。
    // 可以输入多条信息，每条信息存储一行。当用户输入：”886”时，程序结束。
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入");

        FileWriter fw = new FileWriter("D:\\it\\a.txt");
        while (true){
            String s = sc.nextLine();//接受一行数据
            if("886".equals(s)){
                break;
            }else{
                fw.write(s);
            }
        }
        fw.close();
    }

    private static void method2() throws IOException {
        //3.拷贝指定图片到项目文件夹下，文件名保持一致。
        FileInputStream fis = new FileInputStream("D:\\it\\a.jpg");
        FileOutputStream fos = new FileOutputStream("D:\\kk\\b.jpg");
        int i;
        while ((i=fis.read())!=-1){
            fos.write(i);
        }
        fos.write(fis.read());
    }

    private static void method1() throws IOException {
        //2.高效字节输入流+高效字节输输出流对文本文件进行复制(2种复制方式)
        BufferedInputStream bis = new BufferedInputStream
                ( new FileInputStream("D:\\it\\a.txt"));//字节缓冲输入流
        BufferedOutputStream bos = new BufferedOutputStream
                ( new FileOutputStream("D:\\kk\\c.txt"));//字节缓冲输出流
        int len;//记录读取的数据的字节数量
        //存储读取的数据
        byte[] byts=new byte[1024];
        while ((len=bis.read(byts))!=-1){
            bos.write(byts,0,len);
        }
        int i;
        while ((i=bis.read())!=-1){
            bos.write(i);
        }
        bos.close();
        bis.close();
    }

    private static void method() throws IOException {
        //1.普通字节输入流+字节输出流对文本文件进行复制(2种复制方式)
        FileInputStream fis = new FileInputStream("D:\\it\\a.txt");//字节输入流
        FileOutputStream fos = new FileOutputStream("D:\\kk\\b.txt");//字节输出流
        int len;
        byte[] byts=new byte[1024];
        while ((len=fis.read(byts))!=-1){
            fos.write(byts,0,len);
        }
        int i;
        while ((i=fis.read())!=-1){
            fos.write(i);
        }
        fis.close();
        fos.close();
    }
}

class Student{
    private String name;
    private String age;
    private String sex;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age='" + age + '\'' +
                ", sex='" + sex + '\'' +
                '}';
    }

    public Student() {
    }

    public Student(String name, String age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }
}